package com.wwwzh.himalayafm.fragment.subfragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.wwwzh.himalayafm.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

public class SubHistoryFragment extends Fragment
{
  private List<Map<String, String>> list;
  private Button subHisCleBtn;
  private RecyclerView subRecycleView;
  private Toolbar subHisTitle;
  private int TAG;

  public static SubHistoryFragment newInstance(int tag) {

    Bundle args = new Bundle();
    args.putInt("isShowTitle",tag);
    SubHistoryFragment fragment = new SubHistoryFragment();
    fragment.setArguments(args);
    return fragment;
  }

  @Override
  public void onCreate(@Nullable Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    TAG = getArguments().getInt("isShowTitle");
    this.list = new ArrayList();
    int i = 0;
    while (i < 30)
    {
     Map<String,String> maps = new HashMap();
      maps.put("title", String.format(Locale.getDefault(), "title %03d",i + 1));
      maps.put("lastListen", String.format(Locale.getDefault(), "lastListen %03d", i + 1));
      maps.put("lastTime", String.format(Locale.getDefault(), "lastTime %03d", i + 1));
      this.list.add(maps);
      i += 1;
    }
  }
  @Override
  public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle)
  {
  View rootView   = paramLayoutInflater.inflate(R.layout.fragment_sub_history, paramViewGroup, false);
  subRecycleView = ((RecyclerView)rootView.findViewById(R.id.SubHistory_RV));
  TextView  subTempTV = (TextView)rootView.findViewById(R.id.SubTempNone_TV);
    this.subHisCleBtn = ((Button)rootView.findViewById(R.id.SubCleHis_Btn));
    if (TAG == 1){
      subHisTitle = (Toolbar) rootView.findViewById(R.id.SubHIsTitle_TL);
      setPlayHisTitleShow();
    }
    if (list == null) {
      subRecycleView.setVisibility(View.GONE);
      subHisCleBtn.setVisibility(View.GONE);
    }else {
      subTempTV.setVisibility(View.GONE);
      SubHistoryRecAdapter  subHistoryRecAdapter = new SubHistoryRecAdapter(getContext(), this.list);
      subRecycleView.setAdapter(subHistoryRecAdapter);
      subRecycleView.addItemDecoration(new MyItemDecorations(1));
    }
    return rootView;
  }
  @Override
  public void onViewCreated(View paramView, @Nullable Bundle paramBundle)
  {
    super.onViewCreated(paramView, paramBundle);
  }

  public void setPlayHisTitleShow(){

    subHisTitle.setVisibility(View.VISIBLE);
    AppCompatActivity appCompatActivity = (AppCompatActivity) getActivity();
    appCompatActivity.setSupportActionBar(subHisTitle);
    ActionBar actionBar = appCompatActivity.getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setTitle("");

  }


}


